﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using QualityRpt.Dao;
using System.Data;

namespace QualityRpt.Service
{
    public class CodeConfigService:BaseService
    {
        private static ICodeConfigDao _impDao = null;
        static CodeConfigService()
        {
            _impDao = CreateDaoInstance("ICodeConfigDao") as ICodeConfigDao;
        }
        public static DataTable GetSchema()
        {
            DataTable rtTable = _impDao.GetList("ID=0");
            return rtTable.Clone();
        }
        public static DataRow Save(DataRow row)
        {
            return _impDao.Save(row);
        }
        public static DataRow Update(DataRow row)
        {
            return _impDao.Update(row);
        }
        public static DataRow Get(long id)
        {
            return _impDao.Get(id);
        }
        public static void Delete(long id)
        {
            _impDao.Delete(id);
        }
        public static DataTable GetList(string where)
        {
            return _impDao.GetList(where);
        }
        public static DataTable GetList(string where, string sort)
        {
            return _impDao.GetList(where, sort);
        }
        const string pass_suc = "0";
		const string obu_nocard = "59";//obu无卡从设备异常代码集中单列出来,设备异常和逻辑异常各分担50%
		const string dev_ex = "1,8,12,13,15,17,30,31,32,33,36,37,40,41,42,43,44,45,51,53,56,57,60,100";//默认设备异常代码集
        const string l_ex = "2,3,4,5,6,7,9,10,11,14,34,35,38,50,52,54,55,58,61,62";//默认逻辑异常代码集
        const string air_dev_ex = "1,8,12,13,15,17,30,31,32,33,36,37,40,41,42,43,44,45,51,53,56,57,60,100";//默认天线设备异常代码集
        const string air_l_ex = "2,3,4,5,6,7,9,10,11,14,34,35,38,50,52,54,55,58,61,62,59";//默认天线逻辑异常代码集,加入obu无卡
        public static string GetOnePassMode()
        {
            return pass_suc;
        }
		public static string GetOBUNOCardMode(){
			DataTable rtTable = CodeConfigService.GetList("DEVICE_ID=" + DeviceService.OBU_DEV + " AND TARGET = 2");//obu无卡
			string rtCode = obu_nocard;
			if (rtTable.Rows.Count > 0)
			{
				rtCode = rtTable.Rows[0]["CONTENT"].ToString();
			}
			return rtCode;
		}
        public static string GetOBUDevExModes()
        {
            DataTable rtTable = CodeConfigService.GetList("DEVICE_ID=" + DeviceService.OBU_DEV + " AND TARGET = 0");//设备异常
            string rtCode = dev_ex;
            if (rtTable.Rows.Count > 0)
            {
                rtCode = rtTable.Rows[0]["CONTENT"].ToString();
            }
            return rtCode;
        }
        public static string GetOBULExModes()
        {
            DataTable rtTable = CodeConfigService.GetList("DEVICE_ID=" + DeviceService.OBU_DEV + " AND TARGET = 1");//逻辑异常
            string rtCode = l_ex;
            if (rtTable.Rows.Count > 0)
            {
                rtCode = rtTable.Rows[0]["CONTENT"].ToString();
            }
            return rtCode;
        }
        public static string GetAIRDevExModes()
        {
            DataTable rtTable = CodeConfigService.GetList("DEVICE_ID=" + DeviceService.AIRWIRE_DEV + " AND TARGET = 0");//设备异常
            string rtCode = air_dev_ex;
            if (rtTable.Rows.Count > 0)
            {
                rtCode = rtTable.Rows[0]["CONTENT"].ToString();
            }
            return rtCode;
        }
        public static string GetAIRLExModes()
        {
            DataTable rtTable = CodeConfigService.GetList("DEVICE_ID=" + DeviceService.AIRWIRE_DEV + " AND TARGET = 1");//逻辑异常
            string rtCode = air_l_ex;
            if (rtTable.Rows.Count > 0)
            {
                rtCode = rtTable.Rows[0]["CONTENT"].ToString();
            }
            return rtCode;
        }
        public static string GetCARDDevExModes()
        {
            DataTable rtTable = CodeConfigService.GetList("DEVICE_ID=" + DeviceService.ICARD_DEV + " AND TARGET = 0");//设备异常
            string rtCode = dev_ex;
            if (rtTable.Rows.Count > 0)
            {
                rtCode = rtTable.Rows[0]["CONTENT"].ToString();
            }
            return rtCode;
        }
        public static string GetCARDLExModes()
        {
            DataTable rtTable = CodeConfigService.GetList("DEVICE_ID=" + DeviceService.ICARD_DEV + " AND TARGET = 1");//逻辑异常
            string rtCode = l_ex;
            if (rtTable.Rows.Count > 0)
            {
                rtCode = rtTable.Rows[0]["CONTENT"].ToString();
            }
            return rtCode;
        }
    }
}
